//
//  DocumentV2CellModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/11/19.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "DocumentV2CellModel.h"

#import "ArticleListData.h"

@interface DocumentV2CellModel ()

@property (nonatomic, readwrite, copy) NSString* title;
@property (nonatomic, readwrite, copy) NSString* name;
@property (nonatomic, readwrite, copy) NSString* extra;
@property (nonatomic, readwrite, copy) NSString* avatarImgurl;
@property (nonatomic, readwrite, copy) NSString* tag;

@end

@implementation DocumentV2CellModel

- (instancetype)initWithData:(id)data cellHeight:(CGFloat)cellHeight
{
    self = [super init];
    if (self)
    {
        NSDictionary* info = data;
        _category = info[@"Category"];
        _data = info[@"Data"];
        
        /// cellHeight+2（2容错）
        _cellHeight = MHUIScaleValue(cellHeight)+2;
        
        @weakify(self);
        [[RACObserve(self, data) distinctUntilChanged] subscribeNext:^(id x)
         {
             @strongify(self);
             
             ArticleListData* aListData = x;
             
             self.title = aListData.title;
             self.name = aListData.from;
             self.extra = [self.category isEqualToString:@"9"] ? @"" : aListData.areaName;
             self.avatarImgurl = aListData.user.wxHeadImg;
             self.tag = @"icon_w";
         }];
    }
    
    return self;
}

@end
